
			$(function() {
				var name = $( "#name" ),
					email = $( "#email" ),
					password = $( "#password" ),
					allFields = $( [] ).add( name ).add( email ).add( password ),
					tips = $( ".validateTips" );
		 
				function updateTips( t ) {
					tips
						.text( t )
						.addClass( "ui-state-highlight" );
					setTimeout(function() {
						tips.removeClass( "ui-state-highlight", 1500 );
					}, 500 );
				}
		 
				function checkLength( o, n, min, max ) {
					if ( o.val().length > max || o.val().length < min ) {
						o.addClass( "ui-state-error" );
						updateTips( "Panjang dari " + $('#customer option:selected').text() + " hanya bisa dari" +
							min + " sampai " + max + " (sesuai jumlah hari)." );
						return false;
					} else {
						return true;
					}
				}
				
		 
				$( "#dialog-form" ).dialog({
					autoOpen: false,
					height: 300,
					width: 350,
					modal: true,
					buttons: {
						"Tambah Payterm": function() {
							var bValid = true;
							allFields.removeClass( "ui-state-error" );
							
							bValid = bValid && checkLength( name, "Hari", 1, 3 );
							bValid = bValid && checkLength( email, "Keterangan", 1, 3 );
						   
		 
							if ( bValid ) {
								$( "#users tbody" ).append( "<tr>" +
									"<td>" + name.val() + "</td>" +
									"<td>" + email.val() + "</td>" +
									"<td>" + password.val() + "</td>" +
								"</tr>" );
								var base_url = "<?php echo base_url(); ?>";
						
								
								$.ajax({
									url: '<?php echo base_url(); ?>invoice/addPayTerm/' + name.val() +'/' +email.val(),
									type: 'POST',
									data:{"bookn": name.val(), "booki": email.val()},
									success: function (result) {
										alert("Penambahan pay term berhasil");
									}
																			 
								}); 
								$("#paytermPlace").load("<?php echo base_url(); ?>invoice/ajaxLoadPayTerm");
								$( this ).dialog( "close" );
								
							}
						},
						Batal: function() {
							$( this ).dialog( "close" );
						}
					},
					close: function() {
						allFields.val( "" ).removeClass( "ui-state-error" );
					}
				});
		 
				$( "#refreshimgX" )
					.button()
					.click(function() {
						
						$( "#dialog-form" ).dialog( "open" );
					});
			});
		